//
//  main.m
//  Runtime之创建类
//
//  Created by rimi on 16/5/30.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import "Person.h"
/**自定义一个函数*/

void customFunction (id self,SEL _cmd){
    NSLog(@"This Object is %p %@",self, NSStringFromSelector( _cmd));
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //1.动态创建对象 创建一个Person继承自NSObject类
        Class newclass = objc_allocateClassPair([NSObject class], "Person", 0);
        //2.注册类
        objc_registerClassPair(newclass);
        //3.为该类增加名为custom的方法
        class_addMethod(newclass , @selector(custom), (IMP)customFunction , "v@:");
        id instanceOfNewclass = [[newclass alloc] init];
        NSLog(@"111");
        [instanceOfNewclass custom];
        NSLog(@"222");
        [instanceOfNewclass release];
    }
    return 0;
}
